<?php

require_once 'common/conn.php';
$result = array();
if (isset($_GET['usercode'])) {
    $usercode = $_GET['usercode'];
}
if (isset($_GET['code'])) {
    $code = $_GET['code'];
}
if (isset($_GET['playedTimes'])) {
    $playedTimes = $_GET['playedTimes'];
}
if (isset($_GET['type'])) {
    $type = $_GET['type'];
}

$db = new DBC();
$result['errorNo'] = 0;
if (isset($type) && isset($usercode) && isset($playedTimes) && isset($code)) {
    if ($type == "music") {
        $type = 4;
    } else {
        $type = 1;
    }
    $sql = "INSERT INTO t_device_product(usercode,flashcode,usedNumberTimes,type,createTime) VALUES('"
            . $usercode . "','" . $code . "'," . $playedTimes . "," . $type . ",now())";    
    if ($db->execute($sql)) {
        $result['errorNo'] = 0;
        $result['errorMsg'] = "";
    } else {
        $result['errorNo'] = 1;
        $result['errorMsg'] = "执行错误";
    }
} else {
    $result['errorNo'] = 1;
    $result['errorMsg'] = "提交参数不完整";
}
echo json_encode($result);
?>
